import { ipcRenderer } from 'electron'
import { IpcScreenRecordingKeys } from '../common/enums/ipc.screenRecording.enum'
export interface IScreenRecordingApi {
  getSources: () => Promise<any>
  startRecording: (options) => Promise<any>
  pauseRecording: (recorderId) => Promise<any>
  resumeRecording: (recorderId) => Promise<any>
  stopRecording: (recorderId) => Promise<any>
  takeFullScreenshot: (options: any) => Promise<any>
  takeRegionScreenshot: () => Promise<any>
  sendRegionSelected: (callback: (region: any) => void) => void
  sendRegionCanceled: (callback: (region: any) => void) => void
}
// 暴露API给渲染进程
export const screenRecordingApi: IScreenRecordingApi = {
  // 录屏相关方法
  getSources: () => ipcRenderer.invoke(IpcScreenRecordingKeys.GET_SOURCES),
  startRecording: (options) => ipcRenderer.invoke(IpcScreenRecordingKeys.START_RECORDING, options),
  pauseRecording: (recorderId) =>
    ipcRenderer.invoke(IpcScreenRecordingKeys.PAUSE_RECORDING, recorderId),
  resumeRecording: (recorderId) =>
    ipcRenderer.invoke(IpcScreenRecordingKeys.RESUME_RECORDING, recorderId),
  stopRecording: (recorderId) =>
    ipcRenderer.invoke(IpcScreenRecordingKeys.STOP_RECORDING, recorderId),

  // 截图相关方法
  takeFullScreenshot: (options) =>
    ipcRenderer.invoke(IpcScreenRecordingKeys.TAKE_FULL_SCREEN_SHOT, options),
  takeRegionScreenshot: () => ipcRenderer.invoke(IpcScreenRecordingKeys.TAKE_REGION_SCREEN_SHOT),

  // 区域选择器相关方法
  sendRegionSelected: (region) => ipcRenderer.send(IpcScreenRecordingKeys.REGION_CANCELED, region),
  sendRegionCanceled: () => ipcRenderer.send(IpcScreenRecordingKeys.REGION_CANCELED)
}
